/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gestionnaire;

import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import modeles.Client;

/**
 *
 * @author MAZID
 */
@Stateless
@LocalBean
public class GestionnaireClient {
    @PersistenceContext(unitName = "VenteDeFilmPU")
    private EntityManager em;
    
    public boolean creerClient(String loginCl, String mdpCl, String nomCl, String pnomCl, String adresse, 
                    String cp, String ville, String pays, String tel, String email){
        try{
        Client client = new Client(loginCl, mdpCl, nomCl, pnomCl, adresse, cp, ville, pays, tel, email);
        em.persist(client);
        return true;
        }
        catch(Exception e){
            return false;
        }
        
        }
        
    //test login et mot de passe des client de la base
   public Client getClientTestLogin(String login, String pwd){
       Query q = em.createQuery("select c from Client c where c.loginCl=:param1 and c.mdpCl=:param2"); 
       q.setParameter("param1", login);
       q.setParameter("param2", pwd);
       Client c = null;
       try{
           c= (Client) q.getSingleResult();
       } catch(Exception e) {
           c=null;
       }
       return c;
   }
   //fonction pour recuperer le client connecté
   public Client getClientLogin(String login){
       Client client = em.find(Client.class, login);
       return client;
      
   }
   public Client getClientPwd(String pwd){
       Client client =em.find(Client.class, pwd);
       return client;
   }
           
    public void persist(Object object) {
        em.persist(object);
    }
    

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
}
